using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;



namespace Open.Data.Persistence.Hashes
{
    //Implements a label for a property
    public sealed class PropertyLabelHash: LabelHash<PropertyInfo>, ITypeLabel
    {
        public PropertyLabelHash(PropertyInfo prop): base(prop)
        {

        }

        public PropertyLabelHash(PropertyInfo prop, LabelHash parent): base(prop, parent)
        {

        }

        public static LabelHash GetBase(PropertyLabelHash label)
        {
            CacheItem cache = Provider.Instance.ReflectionCache.Lookup(label.Item.PropertyType);

            if (!cache.IsUnderlying)
            {
                TypeLabelHash typeLabel = new TypeLabelHash(cache.BaseType, label);
                return TypeLabelHash.GetBase(typeLabel);
            }

            return label;
        }

        //Returns the underlying type for the label for the ITypeLabel interface
        public Type Type
        {
            get
            {
                return Item.PropertyType;
            }
        }

        public override string ToString()
        {
            return Item.Name;
        }
    }
}